package com.bdqn.ordersystem.service.impl;

import com.bdqn.ordersystem.dao.OrderDao;
import com.bdqn.ordersystem.pojo.Order;
import com.bdqn.ordersystem.service.OrderService;
import com.bdqn.ordersystem.utils.Pager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("orderService")
public class OrderServiceImpl implements OrderService {

    @Resource
    private OrderDao orderDao;


    @Override
    public Order get(Integer id) {
        return orderDao.selectById(id);
    }

    @Override
    public List<Order> listByCondition(Order order){ return orderDao.selectByCondition(order); }

    @Override
    public boolean add(Order order) {
        return orderDao.insert(order)>0;
    }

    @Override
    public boolean modifyRecevie(int id, String recevieBy) {
        return orderDao.updateReceive(id,recevieBy)>0;
    }

    @Override
    public boolean modifyEnd(int id, String resume, String logPath) {
        return orderDao.updateEnd(id,resume,logPath)>0;
    }

    @Override
    public boolean modifyStatus(int id, int status) {
        return orderDao.updateCancel(id,status)>0;
    }

    @Override
    public boolean remove(int id) {
        return orderDao.delete(id)>0;
    }

    @Override
    public Pager<Order> listByPage(Integer areaId, Integer centerId, String address, Integer pageIndex, Integer pageSize) {
        //如果当前页码不存在或者为空，默认当作为第一页
        //查询的是在途工单的数据
        if(null==pageIndex){
            pageIndex=1;
        }
        Pager<Order>pager=new Pager<>();
        pager.setPageIndex(pageIndex);
        pager.setPageSize(pageSize);
        pager.setTotalCount(orderDao.selectCount(areaId,centerId,address));
        pager.setList(orderDao.select(areaId,centerId,address,(pageIndex-1)*pageSize,pageSize));
        return pager;
    }

    @Override
    public Pager<Order> listByPage1(Integer areaId, Integer centerId, String address, Integer pageIndex, Integer pageSize) {
        //如果当前页码不存在或者为空，默认当作为第一页
        //查询的是待处理工单的数据
        if(null==pageIndex){
            pageIndex=1;
        }
        Pager<Order>pager=new Pager<>();
        pager.setPageIndex(pageIndex);
        pager.setPageSize(pageSize);
        pager.setTotalCount(orderDao.selectCount(areaId,centerId,address));
        pager.setList(orderDao.select1(areaId,centerId,address,(pageIndex-1)*pageSize,pageSize));
        return pager;
    }


}
